class Keben {
    public int deleteAndEarn(int[] nums) {
        int[] temp = new int[2000];
        for(int i = 0; i < nums.length; i++) {
            temp[nums[i]] += nums[i];
        }
        int[] dp = new int[temp.length];
        dp[0] = 0;
        dp[1] = temp[1];
        for(int i = 2; i < dp.length; i++) {
            dp[i] = Math.max(dp[i-1],dp[i-2] + temp[i]);
        }
        return dp[dp.length-1];
    }
} 